﻿namespace MSBuild.MKS.Tasks
{
    using System;

    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;

    /// <summary>
    /// The resync.
    /// </summary>
    public class Resync : Task
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets Timeout.
        /// </summary>
        [Required]
        public int Timeout { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns>
        /// The execution result.
        /// </returns>
        public override bool Execute()
        {
            try
            {
                var cmds = new MksCommands { Log = this.Log };
                cmds.Resync(this.Timeout);

                return true;
            }
            catch (Exception ex)
            {
                this.Log.LogError("Exception during {0} procedure: {1}", this.GetType().Name, ex.GetType().Name);
                this.Log.LogError("Exception details: {0}", ex.Message);
                return false;
            }
        }

        #endregion
    }
}